package game.tileMap.control
{
	import com.greensock.TweenLite;
	
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.events.MouseEvent;
	
	import game.tileMap.GameScene;
	import game.tileMap.model.Battler;
	import game.tileMap.model.GameMapModel;
	import game.tileMap.model.Troop;
	import game.tileMap.view.TileMapView;
	
	import mx.core.UIComponent;
	
	import spark.components.Button;
	

	public class AIController extends EventDispatcher
	{
		private var map:GameMapModel
		private var scene:GameScene;
		//private var master:Master
		private var mapView:TileMapView
		public function AIController(scene:GameScene)
		{
			
			this.scene=scene
			map=scene.map
			mapView=scene.mapView;
			init()
		}
		
		
		
//		private function get battleScene():BattleScene{
//			return view.battleScene as BattleScene;
//		}
//		
//		
		
//		private function get cpu():CPUMaster{
//			return appProxy.cpuMaster ;
//		}
		
		private function init():void{
			
			//map.addEventListener(Map.START_BATTLE,startFight);
			map.addEventListener(GameMapModel.NEXT_TROOP,moveUnitHandler);
			//warScene.battleScene.addEventListener(MouseEvent.CLICK,clickBattleScene);
			//mapView.tileBox.addEventListener(MouseEvent.CLICK, clickTile);
			//warScene.battleScene.battleModel=mapView.map.battleModel
//			battleScene.visible=false;
//			master=new Master(warScene.mapView);
//			
//			
//			warScene.mapView.makePlayer();
		}
		
		
		//开始新回合
		private function startNewTurn(event:Event):void{
//			appProxy.cpuMaster.act2();
//			
			/*if (map.turnSide==0){
				mapView.resetTurn();
			}else{
				master.startAct();
			}*/
			
		}
		
		
		

		
		
		private function moveUnitHandler(event:Event):void{
			if (map.turnSide>0){
				var troop:Troop=map.curTroop
				for (var i:int=0;i<troop.members.length;i++){
					var battler:Battler=troop.members[i]
						battler.y+=1;
				}
			}
			
		}
		
		
		
		private function showAction():void{
			
		}
		
		private function selectAct(event:Event):void{
			/*var btn:UIComponent=event.target as UIComponent
				switch (btn.id){
					case "moveBtn":
						break;
					case "attackBtn":
						mapView.showAttack(map.curUnit);
						break;
					case "waitBtn":
						mapView.endAction(mapView.curUnitSp);
						break;
					case "cancelBtn":
						break;
				}
				warScene.cmdBox.visible=false;*/
			
		}
		
		private function startFight(evt:Event=null):void{
			//var battler:Battler=map.curUnit as Battler;
			//map.startBattle(battler,battler.action.actTargets[0] as Battler);
			/*warScene.battleScene.visible=true
			mapView.clearRange();
			warScene.battleScene.play();*/
		}
		private function clickBattleScene(evt:Event):void{
			/*warScene.battleScene.visible=false;
			mapView.endAction(mapView.curUnitSp);
			if (map.checkEndTurn()){
				map.nextTroop();
			}else if (map.turnSide>0){
				TweenLite.delayedCall(1,master.act2);
			}*/
		}
		
	}
}